package com.itheima.controller;

import com.itheima.domain.OmsCompanyAddress;
import com.itheima.domain.OmsOrderReturnApply;
import com.itheima.manager.OmsOrderReturnApplyManager;
import com.itheima.util.R;
import com.itheima.vo.PageBeanVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController

public class OmsOrderReturnApplyController {
    @Autowired
    private OmsOrderReturnApplyManager omsOrderReturnApplyManager;

    //根据id 删除订单信息
    @PostMapping("/returnApply/delete")
    public R delete(@RequestParam List<Integer> ids) {
        System.out.println(ids);
        omsOrderReturnApplyManager.delete(ids);
        return R.success(null);
    }

    // 分页条件查询
    @GetMapping("/returnApply/list")
    public R getList(
            @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
            @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
            String createTime,
            String handleMan,
            String handleTime,
            Integer id,
            String receiverKeyword,
            Integer status) {
/*        System.out.println(createTime);  //申请时间  精确查询
        System.out.println(handleMan);  //处理人员
        System.out.println(handleTime);  //处理时间
        System.out.println(id);             // 服务单号
        System.out.println(receiverKeyword);    // 收货人姓名
        System.out.println(status);         // 0->待处理；1->退货中；2->已完成；3->已拒绝*/
        Map<String, Object> map = new HashMap<>();
        PageBeanVo pageBeanVo = omsOrderReturnApplyManager.getList(pageNum, pageSize, createTime, handleMan, handleTime, id, receiverKeyword, status);
        return R.success(pageBeanVo);
    }

    //修改退货申请状态
    @PostMapping("/returnApply/update/status/{id}")
    public R UpdateStatus(@PathVariable Integer id,
        @RequestBody OmsOrderReturnApply omsOrderReturnApply
    ){
        System.out.println(id);
        System.out.println(omsOrderReturnApply.toString());
        omsOrderReturnApplyManager.updateStatus(id,omsOrderReturnApply);
        return R.success(null);
    }
    // 获取退货申请详情
    @GetMapping("/returnApply/{id}")
    public R particulars(@PathVariable Integer id){
        OmsOrderReturnApply omsOrderReturnApply= omsOrderReturnApplyManager.particulars(id);
        return R.success(omsOrderReturnApply);
    }

    // 获取所有收获地址
    @GetMapping("/companyAddress/list")
    public R companyAddressList(){
        List<OmsCompanyAddress> omsCompanyAddress= omsOrderReturnApplyManager.companyAddressList();
        return R.success(omsCompanyAddress);
    }

}
